<?php

namespace App\Http\Requests\Admin\Customer;

use App\Http\Requests\ApiRequest;
use App\Services\Presenters\HmSkinData;
use Illuminate\Validation\Rule;

/**
 * @property string keywords
 * @property string born_at_start_time
 * @property string born_at_end_time
 * @property string has_skin_record
 * @property string|null sex
 *
 * @property string hm
 * @property string wax
 *
 * @property string|null filter_hm
 * @property string|null hm_label
 * @property string|null hm_label_key
 * @property string|null hm_position
 *
 * @property string|null filter_wax
 * @property string|null wax_itemsid
 * @property string|null wax_levelsort
 * @property string[]|array age_range
 */
class WechatUserIndexRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'keywords'           => 'nullable|string',
            'born_at_start_time' => 'nullable|date',
            'born_at_end_time'   => 'nullable|date',
            'has_skin_record'    => 'nullable|numeric|in:0,1',
            'sex'                => 'nullable|int|in:0,1,2',

            'age_range'      => 'nullable|array|size:2',
            'age_range.*'    => 'required|int|between:1,100',

            'filter_hm'    => 'nullable|bool',
            'hm_label'     => ['required_with:filter_hm', Rule::in(HmSkinData::ITEM_LABELS)],
            'hm_label_key' => 'required_with:filter_hm|string',
            'hm_position'  => 'required_with:filter_hm|int|between:1,4',

            'filter_wax'     => 'nullable|bool',
            'wax_itemsid'    => 'required_with:filter_wax|int|between:1,5',
            'wax_levelsort'  => 'required_with:filter_wax|int|between:1,4',
        ];
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'keyword.*'            => '搜索条件必须是字符串',
//            'born_at_start_time.*' => '开始时间必须是合法的日期',
//            'born_at_end_time.*'   => '截止时间必须是合法的日期',
//            'has_skin_record.*'    => '是否有检测数据必须是数值1或2',
//        ];
//    }
}
